# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :run_cases.py
# @Time      :2024/12/5 11:18:19
# @Author    :flower
import multiprocessing
import os
import shutil
import time

import pytest

from util.get_robot import GetRobot


def generate_allure():
    report_dir = './report'
    if os.path.exists(report_dir):
        shutil.rmtree(report_dir)
    # 生成测试数据
    pytest.main(['--alluredir=./report/result'])
    # 生成测试报告
    os.system('allure generate ./report/result -O ./allure-report/index.html --clean')
    # os.system('allure serve --port 9090 ./report/result')


if __name__ == '__main__':
    pass

    # report_dir = './report'
    # if os.path.exists(report_dir):
    #     shutil.rmtree(report_dir)
    # # 生成测试数据
    # pytest.main(['--alluredir=./report/result'])
    # #
    # # # 两种方式打开报告
    # # # allure serve
    # # os.system('allure serve --port 9090 ./report')
    #
    #
    # # GetRobot().dingtalk_robot(webhook_1='https://oapi.dingtalk.com/robot/send?access_token=9295d0b2177891558c64c519e801adad9ca34461287d89f7ae6bfbbed6b44ded', secret_1='SEC238b8f2a899e15339701f60ef95f42421f9867faa1a10082903ec2b2c6944cbe')
    # # allure open
    # #生成测试报告
    # os.system('allure generate ./report/result -O ./allure-report/index.html --clean')
    # # os.system('allure open allure-report')
    # os.system('allure serve --port 9090 ./report/result')
    # 执行生成allure报告

    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=9295d0b2177891558c64c519e801adad9ca34461287d89f7ae6bfbbed6b44ded'
    secrets = 'SEC238b8f2a899e15339701f60ef95f42421f9867faa1a10082903ec2b2c6944cbe'
    a = multiprocessing.Process(target=generate_allure())
    # 执行发送钉钉机器人
    b = multiprocessing.Process(target=GetRobot().dingtalk_robot(webhook_1=webhook, secret_1=secrets))
    print('-------------------开始执行a')
    a.start()
    print('-------------------结束a')
    time.sleep(2)
    print('-------------------开始执行b')
    b.start()
    print('-------------------结束b')
